const KoaRouter = require('@koa/router')
const postRouter = new KoaRouter({ prefix: '/posts' })
const postController = require('../controller/post.controller')
const { verifyAuthorization } = require('../middleware/login.middleware')
const {
	verifyOperatePost,
	verifyAdminOnly
} = require('../middleware/permission.middleware')
const { verifyLike, verifyFavority } = require('../middleware/post.middleware')
// 1. 创建帖子
postRouter.post('/', verifyAuthorization, postController.create)

// 2. 更新帖子
postRouter.post(
	'/:post_id',
	verifyAuthorization,
	verifyOperatePost,
	postController.update
)

// 3. 删除帖子
postRouter.delete(
	'/:post_id',
	verifyAuthorization,
	verifyOperatePost,
	postController.remove
)

// 4. 查询帖子
postRouter.get('/', postController.findPost)

// 5.修改帖子状态
postRouter.post(
	'/:post_id/status',
	verifyAuthorization,
	verifyAdminOnly,
	postController.updatePostStatus
)

// 6. 根据id查找帖子
postRouter.get('/single/:post_id', postController.findPostById)

// 7. 根据id点赞帖子
postRouter.put(
	'/:post_id/like',
	verifyAuthorization,
	verifyLike,
	postController.likePost
)
// 8.根据id收藏帖子
postRouter.put(
	'/:post_id/collection',
	verifyAuthorization,
	verifyFavority,
	postController.collectePost
)
// 9.根据id查询收藏的帖子
postRouter.get('/collection', verifyAuthorization, postController.findPostsById)

// 10.根据帖子id查询收藏的人
postRouter.get(
	'/collection/:post_id/user',
	postController.findCollectionUserById
)
// 11.根据帖子id查询点赞的人
postRouter.get('/like/:post_id/user', postController.findLikeUserById)

// 12.查找用户发布的帖子
postRouter.get('/mine/post', verifyAuthorization, postController.findMinePost)

// 根据用户id查询发帖子的人
postRouter.get('/user/:user_id/post', postController.finePostByUserId)
module.exports = postRouter
